#include <math.h>

#ifndef M_E
#define M_E        2.71828182845904523536
#endif
#ifndef M_PI
#define M_PI       3.14159265358979323846
#endif

double _Normal_distribution(double x)
{
	int negative;
	double t, ix, poly;
	if(x < 0)
	{
		negative = 1;
		ix = -x;
	}
	else if(x > 0)
	{
		negative = 0;
		ix = x;
	}
	else
		return 0.5;

	t = 1 /(1 + 0.33267 * ix);
	poly = 0.4361836 * t - 0.1201676 * t * t + 0.9372986 * t * t * t;
	t = exp((-ix * ix) / 2) * poly / sqrt(2 * M_PI);
	if(negative)
		return t;
	else
		return 1 - t;
}
